﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Accredit.ascx.cs" Inherits="Hxsoft.AppV1.Admin.RoleManage.Controls.Accredit" %>

<script language="javascript" type="text/javascript">
<!--
function <%# this.ClientID %>_SetResourceGroupExpanded( resourceId )
{
	var containerID = "<%# RptResourceList.ClientID %>";
	var i = document.getElementById( containerID + "_GroupCollapseImg" + resourceId );
	var g = document.getElementById( containerID + "_ResourceGroup" + resourceId );
	
	var imgMinus = new Image();
	var imgPlus = new Image();
	imgMinus.src = "../I/fk_minus.gif";
	imgPlus.src = "../I/fk_plus.gif";
	
	if( i && g )
	{
		if( g.style.display == "none" )
		{
			i.src = imgMinus.src;
			g.style.display = "block";
		}
		else
		{
			i.src = imgPlus.src;
			g.style.display = "none";
		}
	}
}

function <%# this.ClientID %>_CheckItem( checkItem, resourceId )
{
	var containerID = "<%# RptResourceList.ClientID %>";
	var itemContainer = document.getElementById(containerID + "_ResourceItem" + resourceId);
	
	checkBoxs = itemContainer.getElementsByTagName("INPUT");
	<%# this.ClientID %>_RelatingChecked(checkBoxs, checkItem);
	
	var isSCNBox = document.getElementById("<%# IsSelectChildNodes.ClientID %>");
	var isSCN = isSCNBox.checked;
	var isSPNBox = document.getElementById("<%# IsSelectParentNode.ClientID %>");
	var isSPN = isSPNBox.checked;
	
	if( isSCN )
		<%# this.ClientID %>_RelatingChildrenChecked( checkItem, resourceId );
	if( isSPN )
		<%# this.ClientID %>_RelatingParentChecked( checkItem, resourceId );
}

// 关联选择
function <%# this.ClientID %>_RelatingChecked(checkBoxs, checkItem)
{
	var checkItemValue = parseInt(checkItem.value);
	
	for(var i = 0; i < checkBoxs.length; i++)
	{
		var checkBox = checkBoxs[i];
		if(checkBox != checkItem)
		{
			var checkBoxValue = parseInt(checkBox.value);
			if(checkBox && checkBox.type == "checkbox" && !checkBox.disabled)
			{
				if(checkItem.checked)
				{
					if((checkItemValue & checkBoxValue) == checkBoxValue) checkBox.checked = true;
				}
				else
				{
					if((checkBoxValue & checkItemValue) == checkItemValue) checkBox.checked = false;
				}
			}
		}
	}
}

//关联子节点的选中状态
function <%# this.ClientID %>_RelatingChildrenChecked( checkItem, resourceId )
{
	var containerID = "<%# RptResourceList.ClientID %>";
	var g = document.getElementById( containerID + "_ResourceGroup" + resourceId );
	
	if( g )
	{
		var i, checkBoxs = g.getElementsByTagName( "INPUT" );
		<%# this.ClientID %>_RelatingChecked(checkBoxs, checkItem);
	}
}

//关联父节点的选中状态
function <%# this.ClientID %>_RelatingParentChecked( checkItem, resourceId )
{
	var containerID = "<%# RptResourceList.ClientID %>";
	var i = document.getElementById( containerID + "_ResourceItem" + resourceId );
	
	if( i )
	{
		var pid = i.pid;
		
		if( pid )
		{
			var pi = document.getElementById( containerID + "_ResourceItem" + pid );
			
			var i, checkBoxs = pi.getElementsByTagName( "INPUT" );
			<%# this.ClientID %>_RelatingChecked(checkBoxs, checkItem);
			
			<%# this.ClientID %>_RelatingParentChecked( checkItem, pid );
		}
	}
}
-->
</script>

<table id="ListBox" border="0" cellpadding="0" cellspacing="0" width="100%" class="FormTable">
	<tr>
		<td class="ValueBox">
			<input id="IsSelectChildNodes" type="checkbox" checked="checked" runat="server" />
			选择时同时关联选中所有子节点<br />
			<input id="IsSelectParentNode" type="checkbox" checked="checked" runat="server" />
			选择时同时关联选中的父节点
			<asp:Repeater ID="RptResourceList" runat="server" 
				OnItemCreated="RptResourceList_ItemCreated" 
				ondatabinding="RptResourceList_DataBinding">
				<HeaderTemplate>
					<table id="List" width="100%">
						<tr>
							<td>
				</HeaderTemplate>
				<ItemTemplate>
					<%# GroupStartTag %>
					<table cellspacing="1" cellpadding="2" width="100%">
						<tr align="center" onmouseover="listItem_mouseOver(this);" onmouseout="listItem_mouseOut(this);"
							class="mouseout">
							<td align="left">
								<asp:HiddenField ID="Identifier_ResourceId" Value='<%# Eval("ResourceId") %>' runat="server" />
								<%# GroupCollapseImgTag%><%# Eval("ResourceName")%>
							</td>
							<td align="right">
								<asp:Label ID="LblPermission" runat="server"></asp:Label>
							</td>
						</tr>
					</table>
				</ItemTemplate>
				<FooterTemplate>
					<%# GroupEndTag %>
					</td> </tr> </table>
				</FooterTemplate>
			</asp:Repeater>
		</td>
	</tr>
</table>